package interfaz;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class NuevaPartida extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel mainPanel;
	private JButton atrasButton;
	private JButton cargarDibujoButton;
	private JButton abrirDibujoButton;
	private JButton jugarDispoButton;
	
	public NuevaPartida() {
		inicializaComponentes();
		pack();
		
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = getSize();
        setLocation(new Point((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.width) / 2));
	}

	private void inicializaComponentes() {
		GridBagConstraints gridBagConstraints;
		
		mainPanel = new JPanel();
		atrasButton = new JButton();
		cargarDibujoButton = new JButton();
		jugarDispoButton = new JButton();
		abrirDibujoButton = new JButton();
		
		setTitle("Link-A-Pix");
		
   		mainPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
	    mainPanel.setMinimumSize(new Dimension(297, 200));
	    mainPanel.setLayout(new GridBagLayout());
	    
	    cargarDibujoButton.setText("Introducir nuevo tablero");
        cargarDibujoButton.setMnemonic('I');
        cargarDibujoButton.setToolTipText("Empezar nuevo juego");
        cargarDibujoButton.setSize(30, 5);
        cargarDibujoButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				cargarDibujoActionPerformed(evt);
			}
		});
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = GridBagConstraints.CENTER;
        gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
        gridBagConstraints.insets = new Insets(6, 6, 6, 12);
        mainPanel.add(cargarDibujoButton, gridBagConstraints);
        
        abrirDibujoButton.setText("Abrir tablero");
        abrirDibujoButton.setMnemonic('U');
        abrirDibujoButton.setToolTipText("Empezar nuevo juego");
        abrirDibujoButton.setSize(30, 5);
        abrirDibujoButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				abrirDibujoActionPerformed(evt);
			}
		});
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = GridBagConstraints.CENTER;
        gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
        gridBagConstraints.insets = new Insets(6, 6, 6, 12);
        mainPanel.add(abrirDibujoButton, gridBagConstraints);
		
	    getContentPane().add(mainPanel, BorderLayout.CENTER);
	    
	    atrasButton.setMnemonic('N');
        atrasButton.setText("Volver");
        atrasButton.setToolTipText("Volver");
        atrasButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                atrasButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
        gridBagConstraints.gridheight = GridBagConstraints.REMAINDER;
        gridBagConstraints.anchor = GridBagConstraints.SOUTHEAST;
        gridBagConstraints.weighty = 1.0;
        mainPanel.add(atrasButton, gridBagConstraints);
	}

	protected void cargarDibujoActionPerformed(ActionEvent evt) {
		this.setVisible(false);
		new Dimensiones().setVisible(true);
	}

	protected void atrasButtonActionPerformed(ActionEvent evt) {
		this.setVisible(false);
		new PaginaPrincipal().setVisible(true);
	}

	private void abrirDibujoActionPerformed(ActionEvent evt) {
		this.setVisible(false);
		new Niveles().setVisible(true);
	}
	
}
